package com.narbeshuber.tablet.lasalara.dbmanager;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class PreferencesHelper {
	
	private final String PREFS_IDENTIFICATOR = "lasa";
	private final String USER_KEY = "uk";
	private final String BOOK_KEY = "bk";
	private final String CHAPTER_KEY = "ck";
	private final String QUESTION_KEY = "qk";
	
	private SharedPreferences sharedPrefs;
	private Context context;
	
	public PreferencesHelper(Context context) {
		this.context = context;
		this.sharedPrefs = this.context.getSharedPreferences(PREFS_IDENTIFICATOR, 0);
	}
	
	public void saveUserKey(String userKey) {
		Editor editor = sharedPrefs.edit();
		editor.putString(USER_KEY, userKey).commit();
	}
	
	public String getUserKey() {
		return sharedPrefs.getString(USER_KEY, null);
	}
	
	public boolean hasUserKey() {
		return sharedPrefs.contains(USER_KEY);
	}
	
	public void saveBookKey(String bookKey) {
		Editor editor = sharedPrefs.edit();
		editor.putString(BOOK_KEY, bookKey).commit();
	}
	
	public String getBookKey() {
		return sharedPrefs.getString(BOOK_KEY, null);
	}
	
	public boolean hasBookKey() {
		return sharedPrefs.contains(BOOK_KEY);
	}
	
	public void saveChapterKey(String chapterKey) {
		Editor editor = sharedPrefs.edit();
		editor.putString(CHAPTER_KEY, chapterKey).commit();
	}
	
	public String getChapterKey() {
		return sharedPrefs.getString(CHAPTER_KEY, null);
	}
	
	public boolean hasChapterKey() {
		return sharedPrefs.contains(CHAPTER_KEY);
	}
	
	public void saveQuestionKey(String question) {
		Editor editor = sharedPrefs.edit();
		editor.putString(QUESTION_KEY, question).commit();
	}
	
	public String getQuestionKey() {
		return sharedPrefs.getString(QUESTION_KEY, null);
	}
	
	public boolean hasQuestionKey() {
		return sharedPrefs.contains(QUESTION_KEY);
	}
	
	public void clearPrefs() {
		sharedPrefs.edit().clear().commit();
	}
	
	public String toString(){
		return sharedPrefs.getString(BOOK_KEY, null)+":"+sharedPrefs.getString(CHAPTER_KEY, null)+":"+sharedPrefs.getString(QUESTION_KEY, null);
	}
}
